TASK_DIR:=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))

include ../../config.mk

# Inputs
RMD_FILE := $(TASK_DIR)/src/gen_realized_risk_table.Rmd
REALIZED_RISK_BY_PATHWAY := $(TASK_DIR)/../../get_realized_risk/output/realized_risk_by_pathway.csv
BASELINE_RISK_BY_PATHWAY := $(TASK_DIR)/../../get_realized_risk/output/baseline_risk_by_pathway.csv
CONFIG_FILE := $(TASK_DIR)/hand/config.yaml

# One of the outputs
OUT_FILE := $(OUT_DIR)/realized_risk_up_to_date.tex

$(OUT_FILE): $(RMD_FILE) $(CONFIG_FILE) $(REALIZED_RISK_BY_PATHWAY) $(BASELINE_RISK_BY_PATHWAY) $(OUTCOME_LABELS_FILE) $(TABLE_CONFIG) $(TABLE_FNS)
	@mkdir -p $(OUT_DIR)
	@mkdir -p $(PAPER_OUT_DIR)
	$(R_script) -e "rmarkdown::render(input = '$(RMD_FILE)')"
	@cp $(OUT_DIR)/*up_to_date.tex $(PAPER_OUT_DIR)

.PHONY: all clean
.DEFAULT_GOAL=all

all: $(OUT_FILE)

clean:
	rm -rf $(OUT_DIR)/*up_to_date*
